package com.payment.controller;

public class ResDTO<T> { // 泛型T，data可以是任何类型
    private int code;
    private String msg;
    private T data; // 使用泛型T

    public ResDTO(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    //成功响应
    public static  <T> ResDTO<T> success(T data) {
        return new ResDTO<>(200, "操作成功！", data);
    }

    //支付成功的响应
    public static  <T> ResDTO<T> success(String orderId,int patientsId,T data) {
        return new ResDTO<>(200, "支付成功！病人id："+patientsId+"；订单号："+orderId, data);
    }

    //失败响应
    public static <T> ResDTO<T> error(String msg) {
        return new ResDTO<>(500, msg, null);
    }

    // 失败响应，使用默认msg
    public static <T> ResDTO<T> error() {
        return error("操作失败！"); // 调用带有msg参数的error方法，传入默认消息
    }
}